package com.test.prolenders.bean_prolenders.userinfo_prolenders;

import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.ArrayList;


public class AccountList_Fr_prolenders {

    private static class Inner {
        private static final AccountList_Fr_prolenders instance = new AccountList_Fr_prolenders();
    }

    private AccountList_Fr_prolenders() {}

    public static AccountList_Fr_prolenders getInstance() {
        return Inner.instance;
    }

    private final ArrayList<BankAccount_Fr_prolenders> bankAccountList = new ArrayList<>();

    private Runnable parseRunnable;

    public static void parse(JSONArray jsonArray) {

        Gson gson = new Gson();
        Inner.instance.bankAccountList.clear();
        for (int i=0;i<jsonArray.length();i++){
            try {
                BankAccount_Fr_prolenders bankAccount = gson.fromJson(jsonArray.get(i).toString(), BankAccount_Fr_prolenders.class );
                Inner.instance.bankAccountList.add(bankAccount);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        if (Inner.instance.parseRunnable!=null) Inner.instance.parseRunnable.run();

    }

    public ArrayList<BankAccount_Fr_prolenders> getBankAccountList() {
        return bankAccountList;
    }

    public void setParseRunnable(Runnable parseRunnable) {
        this.parseRunnable = parseRunnable;
    }
}
